Skip to content

firefox bug scroll instead of volume#3663

Draft
MoriMomo wants to merge 4 commits intocode-charity:masterfrom
MoriMomo:master
Draft

firefox bug scroll instead of volume#3663
MoriMomo wants to merge 4 commits intocode-charity:masterfrom
MoriMomo:master

Conversation

@MoriMomo
Copy link
Contributor

@MoriMomo MoriMomo commented Mar 4, 2026

Fix: Keyboard shortcuts not working when player isn't focused (Firefox)

The Problem

yo so, so keyboard shortcuts weren't working on Firefox-based browsers (Firefox, Floorp, Librewolf, etc.) when the video player wasn't in focus. For example, if you set Up/Down arrow keys to control volume, they would just scroll the page instead of changing the volume - unless you clicked on the player first.

it kinda worked fine in Chrome, but was broken in Firefox. Pretty annoying when you're reading comments and want to quickly adjust volume!

What Was Wrong

The shortcut handler was checking document.activeElement to see if the user was typing in an input field. This check was too strict in Firefox - it would incorrectly think the player needed focus for shortcuts to work, when really we just need to make sure the user isn't typing in a text field.

The Fix

Two changes to make it work properly:

  1. Better event target checking - Now we check event.target first (the actual element that received the keypress) instead of relying on document.activeElement. This is more reliable across all browsers, especially Firefox.

  2. Added document-level listeners - Added keyboard event listeners to document in addition to window for better Firefox compatibility. This ensures we catch all keyboard events, even when YouTube's complex DOM structure is involved.

Testing

Tested on:

  • Firefox 124

To test:

  1. Set any shortcut (like Up/Down for volume)
  2. Play a video
  3. Click anywhere EXCEPT the player (comments, sidebar, etc.)
  4. Press your shortcut key
  5. Should work now! 🎉

The fix still correctly prevents shortcuts from working when you're actually typing in input fields or the search box.

Files Changed

  • js&css/web-accessible/www.youtube.com/shortcuts.js - Updated event handler and listener initialization

Fixes ##3639

@ImprovedTube
Copy link
Member

@ImprovedTube
Copy link
Member

#3659 was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants